<?php

namespace app\admin\controller;

class Login extends \think\Controller
{
    /**
     * 显示登录界面
     * @return \think\response\View
     */
    public function login()
    {
        if (session("admin_id")) {
            $this->redirect("admin/data/show_data");
        } else {
            return view();
        }
    }

    /**
     * 确认登录信息
     * @param string $username
     * @param string $password
     */
    public function confirm_login($username = "", $password = "")
    {
        $key = db('user')->where('account', $username)->value('key');
        if ($key) {
            $all_password = $password . $key;
            $id = db('user')->where('password', md5($all_password))->value('id');
            if ($id) {
                session("admin_id", $id);
                php_alert("登录成功", "success", false, "../data/show_data");
            } else {

                php_alert("验证码错误", "error", true);
            }
        } else {
            php_alert("账号不存在", "error", true);
        }
    }

    /**
     * 退出系统
     */
    public function exit_system()
    {
        session(null);
        $this->success('退出成功', 'admin/login/login');
    }
}